<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="料号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemNo">
              <a-input v-model="model.itemNo" placeholder="请输入料号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manufactureDate">
              <a-input v-model="model.manufactureDate" @change="handleChange" placeholder="请输入生产日期"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="生产批号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lotNo">
              <a-input v-model="model.lotNo" placeholder="请输入生产批号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="版本" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="edition">
              <a-input v-model="model.edition" placeholder="请输入版本"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="总数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalNum">
              <a-input v-model="model.totalNum" placeholder="请输入总数"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="内/外箱数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outerBoxesNum">
              <a-input v-model="model.outerBoxesNum" placeholder="最小包装的数量"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="模穴号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moldCavityNo">
              <a-input v-model="model.moldCavityNo" placeholder="无模穴号填0"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="机种名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="modelName">
              <a-input v-model="model.modelName" placeholder="请输入机种名"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <a-input v-model="model.productName" placeholder="请输入品名"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="包装日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="packingDate">
              <a-input v-model="model.packingDate" placeholder="默认等于填的生产日期"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="材质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialTexture">
              <a-input v-model="model.materialTexture" placeholder="请输入材质"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="色号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="colorCode">
              <a-input v-model="model.colorCode" placeholder="请输入色号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="内箱外箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outerBox">
              <a-select v-model="model.outerBox" placeholder="请选择外箱或者内箱">
                <a-select-option value="B">
                  外箱
                </a-select-option>
                <a-select-option value="I">
                  内箱
                </a-select-option>
              </a-select>
              <!-- <a-radio-group v-model="model.outerBox" defaultValue="1" @change="onChange">
                <a-radio :value="1">
                  外箱
                </a-radio>
                <a-radio :value="2">
                  内箱
                </a-radio>
              </a-radio-group> -->
              <!-- <a-radio-group buttonStyle="solid" v-decorator="[ 'status', {'initialValue':B}]">
                <a-radio-button :value="B">正常</a-radio-button>
                <a-radio-button :value="I">停止</a-radio-button>
              </a-radio-group> -->
            </a-form-model-item>

          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="箱号（条码总长18位）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reelId">
              <a-input v-model="model.reelId" placeholder="请输入箱号（条码总长18位）"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="二维码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qrCode">
              <a-input v-model="model.qrCode" placeholder="请输入二维码"></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="8">
            <a-form-model-item label="AA1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="aa1">
              <a-input v-model="model.aa1" placeholder="请输入AA1"></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-model-item label="AA2(reelId的前12位)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="aa2">
              <a-input v-model="model.aa2" placeholder="请输入AA2(reelId的前12位)"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="流水号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serialNumber">
              <a-input v-model="model.serialNumber" placeholder="请输入流水号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="箱数(默认1)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="casesNum">
              <a-input v-model="model.casesNum" placeholder="请输入箱数(默认1)"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item
              label="尾数数量(默认为0)"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mantissaQuantity"
            >
              <a-input v-model="model.mantissaQuantity" placeholder="请输入尾数数量(默认为0)"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="打印地点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="printLocation">
              <a-select style="width: 120px" @change="handleChange" v-model="model.printLocation">
                <a-select-option v-for="(item, index) in printLocationList" :key="index" :value="item.value">
                  {{ item.text }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'ChAssociationPrintForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      value: '1',
      model: {
        printLocation: '02',
        outerBox: 'B',
        moldCavityNo: 0,
        edition: 0,
        manufactureDate:JSON.parse(localStorage.getItem("data")),
        lotNo:JSON.parse(localStorage.getItem("data1")),
        packingDate:JSON.parse(localStorage.getItem("data")),
        aa1:'I15059'
      },
      printLocationList: [
        {
          text: '河源昌红',
          value: '01'
        },
        {
          text: '昌红注塑部',
          value: '02'
        }
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      // 表单校验规格
      validatorRules: {
        // 料号
        itemNo: [
          { required: true, message: '请输入料号', trigger: 'blur' },

        ],
        // 生产日期
        manufactureDate: [
          { required: true, message: '请输入生产日期', trigger: 'blur' },
        ],
        // 生产批号
        lotNo: [
          { required: true, message: '请输入生产批号', trigger: 'blur' },
        ],
        // 版本
        edition: [
          { required: true, message: '请输入版本', trigger: 'blur' },
        ],
        // 总数
        totalNum: [
          { required: true, message: '请输入总数', trigger: 'blur' },
        ],
        // 外箱数量
        outerBoxesNum: [
          { required: true, message: '请输入外箱数量', trigger: 'blur' }
        ],
        // 模穴号
        moldCavityNo: [
          { required: true, message: '请输入模穴号', trigger: 'blur' }
        ],
        // 机种名
        // modelName: [
        //   { required: true, message: '请输入机种名', trigger: 'blur' },
        // ],
        // 品名
        productName: [
          { required: true, message: '请输入品名', trigger: 'blur' },
        ],
        // 包装日期
        packingDate: [
          { required: true, message: '请输入包装日期', trigger: 'blur' },
        ],
        // 材质
        // materialTexture: [
        //   { required: true, message: '请输入材质', trigger: 'blur' },
        // ],
        // 色号
        colorCode: [
          { required: true, message: '请输入色号', trigger: 'blur' },
        ],
        // 是否外箱
        outerBox: [
          { required: true, message: '请选择是或者否', trigger: 'blur' },
        ],
        // 是否外箱
        aa1: [
          { required: true, message: '请AA1', trigger: 'blur' },
        ],



        // type: [
        //   {
        //     type: 'array',
        //     required: true,
        //     message: 'Please select at least one activity type',
        //     trigger: 'change',
        //   },
        // ],
        // resource: [
        //   { required: true, message: 'Please select activity resource', trigger: 'change' },
        // ],
        // desc: [{ required: true, message: 'Please input activity form', trigger: 'blur' }],
      },
      url: {
        add: '/ch/chAssociationPrint/add',
        edit: '/ch/chAssociationPrint/edit',
        queryById: '/ch/chAssociationPrint/queryById',
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    // 生产时间
    this.dataCreate()
    console.log("this",this);
  },
  mounted(){
    // 生产时间
    // this.dataCreate()
   
  },
  methods: {  
    handleChange(e) {
      console.log("eeeee",e.target.value);
      this.model.lotNo = e.target.value + 'D'
      this.model.packingDate = e.target.value
    },
    // 时间初始值
    dataCreate(){
      var date = new Date();
        var year = date.getFullYear().toString().slice(2);
        var month = (date.getMonth() + 1).toString();
        var day = date.getDate().toString();
        month = (month > 9) ? month : ("0" + month);
        day = (day < 10) ? ("0" + day) : day;
        var today = year + month + day;
        var today1 = year + month + day + 'D';

        console.log('date', date);
        console.log('year', year);
        console.log('month', month);
        console.log('day', day);
        console.log("today",today);
        console.log("this111",this);
        // this.$set(this.model,'manufactureDate',today )
        // 将today的数据存储入data,需提前转化成string类型
        localStorage.setItem("data", JSON.stringify(today));
        localStorage.setItem("data1", JSON.stringify(today1));
        //取
        // JSON.parse(localStorage.getItem("today"));
        // this.model.manufactureDate = year + month + day;
    },
    onChange(e) {
      console.log('e.target.value', e.target.value);
      // if (e.target.value == 1) {
      //   this.model.outerBox ='B'     
      // }else{
      //   this.model.outerBox ='I'
      // }
      console.log('this.model.outerBox', this.model.outerBox);
    },
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              console.log('ressss:', res);
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
  },
}
</script>